<?php
$stu_id = $_POST['stu_id'];
$stu_name = $_POST['stu_name'];
$stu_password = $_POST['stu_password'];
$stu_phone_num = $_POST['stu_phone_num'];
$stu_age = $_POST['stu_age'];
$stu_sex = $_POST['stu_sex'];

$db_host = 'localhost';
$db_name = 'big_data_221';
$db_user = 'class_page';
$db_pwd = '1';
$table_name = 'student';

//创建数据库查询
$mysqli = new mysqli($db_host, $db_user, $db_pwd, $db_name);
//预处理SQL语句
$sql_select = 'select * from ' . $table_name . ' where stu_id = ' . $stu_id;
// 执行查询
$result = $mysqli->query($sql_select);
if ($result->num_rows == 1) {
    echo 'nihao';
    header('Location:user_login.php');
} else {
    $sql_insert = $mysqli->prepare("INSERT INTO $table_name VALUES (?,?,?,?,?,?)");
    $sql_insert->bind_param('isiiis', $stu_id, $stu_name, $stu_password, $stu_phone_num, $stu_age, $stu_sex);
    $sql_insert->execute();
    header('Location:user_register.html');
}
$mysqli->close();
?>
